package com.ygly.struts.pro;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.ygly.struts.actions.ContextAction;
import com.ygly.struts.actions.SqlAction;
import com.ygly.struts.models.User;

public class AttendPro extends ActionSupport {

	/**
	 * @return
	 */
	public String execute()throws Exception {
		// TODO Auto-generated method stub
		ActionContext con = ActionContext.getContext();
		HttpServletRequest request = (HttpServletRequest )con.get(ServletActionContext.HTTP_REQUEST);
		int proid = Integer.parseInt(request.getParameter("proid"));
		String proname = request.getParameter("proname");
		int comid = Integer.parseInt(request.getParameter("comid"));
		String comname = request.getParameter("comname");
		ActionContext ctx = ActionContext.getContext();
		Map session = ctx.getSession();
		User user2 = (User )session.get("user");
		int stuid = user2.getId();
		String stuname = user2.getName();
		Date dt = new Date();
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String createtime = df.format(dt);
		String query = "INSERT INTO `ygly`.`stu_pro` (`Stu_Id`, `Stu_Name`, `Pro_Id`, `Pro_Name`, `Com_Id`, " +
				"`Com_Name`, `State`, `Createtime`, `Grade`) VALUES ('"+stuid+"', '"+stuname+"', '"+proid+"', " +
						"'"+proname+"', '"+comid+"', '"+comname+"', '0', '"+createtime+"', '0');";
		SqlAction sql = new SqlAction();
		sql.OpenConn();
		System.out.print("!!");
		sql.executeUpdata(query);
		return "SUCCESS";
	}
}